import request from '@/utils/request';
import type { ResponseData } from '../typing';
// 参数接口
export interface UpdateTenantParams {
    /*名称 */
    name: string;

    /*角色ID */
    roleIds: Record<string, unknown>[];

    /*主键 */
    id: number;
}

/**
 * 更新租户
 * @param {object} params 管理后台 - 租户更新 Request VO
 * @param {string} params.name 名称
 * @param {array} params.roleIds 角色ID
 * @param {number} params.id 主键
 * @returns
 */
export function updateTenant(params: UpdateTenantParams): Promise<ResponseData<boolean>> {
    return request.put(`/system/tenant`, params);
}
// 响应接口
export interface GetTenantPageRes {
    /* */
    code: number;

    /* */
    data: {
        /* */
        size: number;

        /* */
        total: number;

        /* */
        current: number;

        /* */
        records: {
            /* */
            createTime: Record<string, unknown>;

            /* */
            updateTime: Record<string, unknown>;

            /* */
            creator: number;

            /* */
            updater: number;

            /*主键 */
            id: number;

            /*系统名称 */
            name: string;
        }[];

        /* */
        pages: number;
    };

    /* */
    msg: string;
}

/**
 * 获得租户分页
 * @param {string} name 系统名称
 * @param {string} current 当前第几页(默认1)
 * @param {string} size 每页条数(默认20)
 * @returns
 */
export function getTenantPage(params: any): Promise<GetTenantPageRes> {
    return request.get(`/system/tenant/page`, { params });
}
// 参数接口
export interface CreateTenantParams {
    /*名称 */
    name: string;

    /*角色ID */
    roleIds: Record<string, unknown>[];
}

/**
 * 创建租户
 * @param {object} params 管理后台 - 租户创建 Request VO
 * @param {string} params.name 名称
 * @param {array} params.roleIds 角色ID
 * @returns
 */
export function createTenant(params: CreateTenantParams): Promise<ResponseData<boolean>> {
    return request.post(`/system/tenant`, params);
}
// 响应接口
export interface GetTenantRes {
    /* */
    code: number;

    /* */
    data: {
        /* */
        createTime: Record<string, unknown>;

        /* */
        updateTime: Record<string, unknown>;

        /* */
        creator: number;

        /* */
        updater: number;

        /*主键 */
        id: number;

        /*系统名称 */
        name: string;

        roleIds: Record<string, unknown>[];
    };

    /* */
    msg: string;
}

/**
 * 获得租户
 * @param {string} id
 * @returns
 */
export function getTenant(id: number): Promise<GetTenantRes> {
    return request.get(`/system/tenant/${id}`);
}

/**
 * 删除租户
 * @param {string} id
 * @returns
 */
export function deleteTenant(id: number): Promise<ResponseData<boolean>> {
    return request.delete(`/system/tenant/${id}`);
}
